import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', () => {
  //定义一个响应式状态
  const user = ref(null);
  //定义getter 方法
  const userInfo = computed(() => {
    return user.value;
  })

  const updateUser = (u) => {
    user.value = u
  }

  const $reset = () =>{
    user.value = null
  };
  return { user, userInfo, updateUser, $reset }
}, {
  persist: {
    key: 'user',
    storage: sessionStorage
  }
})
